/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : 
  * Description        : 
  ******************************************************************************
  * @attention
  *
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "utils_math.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
/**
  * @brief  read digital quantity are converted to angles, unit of angle in radians
  * @note   
  * @param  uint32_t number:angle digital always greater than zero
						uint32_t range:range from zero to 2^N, depend on encoder resolution
  * @retval 
  */
float utils_digital_radians(int32_t number,uint32_t range)
{
	float calc;
	//limit = number % range;
	calc = (float)number / (float)(range);
	calc = calc * TWO_PI;
	//calc = calc - PI;
	return calc;
}

void utils_limit_float(float * x, float min, float max)
{
	*x = *x > min ? *x : min;
	*x = *x < max ? *x : max;
}

void utils_limit_single_angle(float * angle)
{
	while (*angle < -PI) { *angle += 2.0f * PI; }
	while (*angle >=  PI) { *angle -= 2.0f * PI; }
}

float utils_min_abs(float va, float vb) {
	float res;
	if ((va) < (vb)) {
		res = va;
	} else {
		res = vb;
	}
	return res;
}
/* USER CODE END Application */

